<?php
namespace app\console\controller;

use think\Url;
use think\Request;
use think\Controller;
use app\console\model\ShopGradeFlag as ShopGradeFlagModel;

class ShopGradeFlag extends Controller
{
    /*
     * 店铺等级列表
     */
    public function index()
    {

        if (Request::instance()->isPost()) {

            if (Request::instance()->param('name')) {

                (new ShopGradeFlagModel())->allowField(true)->save(Request::instance()->param());

            }

            $ids = Request::instance()->param('ids/a');
            $name = Request::instance()->param('shopName/a');
            $number = Request::instance()->param('shopNumber/a');
            $money = Request::instance()->param('shopMoney/a');

            for ($i = 0; $i < count($ids); $i++) {
                (new ShopGradeFlagModel)->where('id', $ids[$i])->update(['name' => $name[$i], 'number' => $number[$i], 'money' => $money[$i]]);
            }

        }

        $data = ShopGradeFlagModel::all();


        return $this->fetch('index', [
            "mate_title" => '店铺等级列表',
            'data'       => $data
        ]);

    }

    /*
     * 店铺等级删除
     */
    public function destroy($id)
    {

        if (ShopGradeFlagModel::destroy($id)) {
            win('操作成功', Url::build('ShopGradeFlag/index'));
        }

        fail('操作失败');

    }
}
